﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using Safover.LidarCollector.Extensions;
using System.Runtime.Serialization;

namespace Safover.Lidar.DataContract
{
    /// <summary>
    /// 原始雷达数据帧，对应一个激光脉冲周期内采集的数据
    /// </summary>
    [DataContract]
    public class LidarRawFrame
    {
        /// <summary>
        /// 扫描事务ID
        /// </summary>
        [DataMember] public string ShortUUID { get; set; }

        /// <summary>
        /// 站点缩写
        /// </summary>
        [DataMember] public string StationAbbreviation { get; set; }

        /// <summary>
        /// 数据采集时，雷达的工作业务模式，包括：定向、水平、垂直、车载，以及混合工作模式
        /// </summary>
        [DataMember] /*[JsonConverter(typeof(StringEnumConverter))]*/ public LidarWorkMode LidarWorkMode { get; set; }

        /// <summary>
        /// 雷达扫描模式
        /// </summary>
        [DataMember] /*[JsonConverter(typeof(StringEnumConverter))]*/ public LidarScanMode LidarScanMode { get; set; }

        /// <summary>
        /// 数据帧所在的周期性采集数据包的起始时间
        /// </summary>
        [DataMember] public long UtcPeriodicScanStartTimestamp { get; set; }

        /// <summary>
        /// 数据帧采集起始UTC时间
        /// </summary>
        [DataMember] public long UtcStartTimestamp { get; set; }

        /// <summary>
        /// 数据帧采集结束UTC时间
        /// </summary>
        [DataMember] public long UtcEndTimestamp { get; set; }

        /// <summary>
        /// 摆动扫描（水平、垂直）模式的起始角
        /// VScan: value = 起始扫描时的水平定角；
        /// HScan：value = 俯仰定角角；
        /// UnderwayScan & FixScan：value = vertical angle = horizontal angle；
        [DataMember] public float StartAngle { get; set; }

        /// <summary>
        /// 摆动扫描（水平、垂直）模式的终止角；【注意，此处为给定值，没有取余的转换逻辑判断】
        /// </summary>
        [DataMember] public float EndAngle { get; set; }

        /// <summary>
        /// 激光水平角
        /// </summary>
        [DataMember] public float HorizontalAngle { get; set; }

        /// <summary>
        /// 激光俯仰角
        /// </summary>
        [DataMember] public float VerticalAngle { get; set; }

        
        /// </summary>
        //[DataMember] public float FixedStartAngle { get; set; }


        /// <summary>
        /// 经度
        /// </summary>
        [DataMember] public double Longitude { get; set; }

        /// <summary>
        /// 纬度
        /// </summary>
        [DataMember] public double Latitude { get; set; }

        /// <summary>
        /// 海拔
        /// </summary>
        [DataMember] public double Altitude { get; set; }

        /// <summary>
        /// 俯仰角
        /// </summary>
        [DataMember] public float PitchAngle { get; set; }

        /// <summary>
        /// 方位角
        /// </summary>
        [DataMember] public float HeadingAngle { get; set; }

        /// <summary>
        /// 横滚角
        /// </summary>
        [DataMember] public float RollAngle { get; set; }


        /// <summary>
        /// 数据帧内的通道数据和通道参数
        /// </summary>
        [DataMember] public LidarRawChannel[] Channels { get; set; }

        public LidarRawFrame() { }

        public override string ToString()
        {
            var bjTime = TimeUtils.UtcTimestamp2BeiJingDateTime(UtcStartTimestamp);
            return $"{StationAbbreviation}-{bjTime:yyyy-MM-dd HH:mm:ss}-{LidarScanMode}: Angle=[{StartAngle}-{EndAngle}], Longitude={Longitude}, Latitude={Latitude}, Channel Number={Channels.Length}";
        }
    }

}
